import os
import datetime
import sys
from pathlib import Path
import pytest
from loguru import logger

from const路径管理 import PATH, TEST_FLOW


def get_report_path():
    report_path = PATH / 'reports'
    report_path.mkdir(exist_ok=True)

    time_smap = datetime.datetime.now().strftime('%Y-%m-%d-%H-%M-%S')

    task_dir = report_path / f'{time_smap}'
    task_dir.mkdir()

    log_path = task_dir / 'log'
    log_path.mkdir()

    log_file = log_path / 'pytest.log'
    logger.add(log_file)

    data_dir = task_dir / 'data'
    html_dir = task_dir / 'html'

    return data_dir, html_dir


def main():
    allure_dir, html_dir = get_report_path()
    pytest.main(['-sv', str(TEST_FLOW), '--alluredir', str(allure_dir)])
    os.system(f'allure generate {allure_dir} -o {html_dir} --single-file')


if __name__ == '__main__':
    main()
